<?php

/**
 * File:userView.php
 * @author: CIS505 ATeam
 * @version: 2012-11-29
 * Purpose: add user form
 */

/**
 * display welcome message
 */
function displayWelcomeMessage( )
{
  echo <<<_END
<div id="wrapper">
  <div id="welcome">
    <strong>User Logins</strong>
  </div> <!-- end #welcome -->
</div> <!-- end #wrapper -->
_END;
}


/**
 * add user data form
 */
function displayUserDataForm( )
{
  echo <<<_END

  <body onLoad="document.forms.addUserForm.foreName.focus()">
  <div id="wrapper">
  <form method="post" action="userControl.php" name="addUserForm" id="addUserForm">
    <fieldset>
      <legend>Add User</legend>
       <div id="left">
        <PRE>
        First Name: <input type="text" name="foreName" size="20" maxlength="20" />
         Last Name: <input type="text" name="surName" size="20" maxlength="20" />
         User Name: <input type="text" name="userName" size="20" maxlength="20" />
            E-Mail: <input type="text" name="eMail" size="20" maxlength="20" />
          Password: <input type="password" name="password" size="21" maxlength="20" />
        </PRE>
       </div><!-- end #left -->

       <div id="right">
        <input type="submit" name="submitBttn" value="Add User" />
       </div> <!-- end #middle -->

    </fieldset>
  </form> <!-- end form -->
  </div> <!-- end #wrapper -->
  <br />
_END;
 
}


/**
 * start user list
 */

function startUserList ( )
{
  $out = <<<_END
  <head>
    <title>Insert Atcomm User</title>
    <link rel="stylesheet" href="../css/cWeb.css" type="text/css" />
  </head> <!-- end head -->

  <body>
    <div id="wrapper">
      <fieldset>
        <legend>User List</legend>
          <table>
            <tr>
              <strong>
                <th>User ID</th>
                <th>First Name</th>
                <th>Last Name</th>
                <th>User Name</th>
                <th>E-Mail</th>
                <th>Add Date</th>
                <th>Update</th>
                <th>Delete</th>
              </strong>
            </tr> <!-- end table row -->

_END;

  return $out;

}

/**
 * display one user
 * has delete button
 * @param $userID
 * @param $foreName
 * @param $surName
 * @param $userName
 * @param $eMail
 * @param $recordAddDate
 *
 */
function displayOneUserList($userID, $foreName, $surName, $userName, $eMail, $recordAddDate)
{
  $out = <<<_END

            <tr>
              <td>$userID</td>
                <form method="post" action="userControl.php">
                  <td><input type="text" name="foreName" id="foreName" value="$foreName" size="10" maxlength="20" /></td>
                  <td><input type="text" name="surName" id="surName" value="$surName" size="10" maxlength="20" /></td>
                  <td><input type="text" name="userName" id="userName" value="$userName" size="10" maxlength="20" /></td>
                  <td><input type="text" name="eMail" id="eMail" value="$eMail" size="10" maxlength="20" /></td>
              <td>$recordAddDate</td>
              <div id="right">
              <td>
                  <input type="hidden" name="userID" id="userID" value="$userID" />
                  <input type="submit" name="update" id="update" value="UPDATE" />
              </td>
              <td>
                  <input type="hidden" name="userID" id="delete" value="$userID" />
                  <input type="submit" class="dbutton" name="delete" id="delete" value="DELETE" />

              </td>
                </form>
              </div>
            </tr> <!-- end table row -->

_END;
  return $out;

}

/**
 * display error message if not empty.
 */
function displayErrorMessage($errorMsg)
{
if ($errorMsg != "") { //echoed only if there is an error to report
    echo "<strong>====ERROR</strong>: $errorMsg. Try again!<br /><br />";
  }
}


/**
 * display user list
 * contains search feature
 */
function displayUserList($userList)
{
  $out = "";
  echo <<<_END
  <div id="wrapper">
    <form method="post" action="userControl.php">
      <fieldset>

        <legend>Search</legend>
        <div id="left">
          <PRE>
         Search BY: <select name = "criteria" size="1" />
              <option value = "userID">User ID</option>
              <option value = "foreName">First Name</option>
              <option value = "surName">Last Name</option>
              <option value = "userName">User Name</option>
              <option value = "eMail">E-Mail</option>
              <option value = "recordAddDate">Add Date</option>
            </select>  Search For: <input type = "text" maxlength = "50" name = "search">
        Outer Sort: <select name = "outerSort" size="1" />
              <option value = "userID">User ID</option>
              <option value = "foreName">First Name</option>
              <option value = "surName">Last Name</option>
              <option SELECTED value = "userName">User Name</option>
              <option value = "eMail">E-Mail</option>
              <option value = "recordAddDate">Add Date</option>
            </select>
        Inner Sort: <select name = "innerSort" size="1" />
              <option value = "userID">User ID</option>
              <option value = "foreName">First Name</option>
              <option value = "surName">Last Name</option>
              <option value = "userName">User Name</option>
              <option value = "eMail">E-Mail</option>
              <option SELECTED value = "recordAddDate">Add Date</option>
            </select>
             Limit: <select name = "howMany" size="1"/>
              <option value = "10">10</option>
              <option SELECTED value = "25">25</option>
              <option value = "50">50</option>
              <option value = "100">100</option>
              <option value = "1000">1000</option>
            </select>
          </PRE>
        </div><!-- end #left" -->

        <div id="right">
          <input type = "submit" name="searchButton" value="Search" />
        </div> <!-- end #right -->


      </fieldset>
    </form>
</div> <!-- end #wrapper -->
<br />
_END;

  $out = startUserList( ) . $userList . closeUserList( );
  echo $out;
}

/**
 * close user list
 */
function closeUserList( )
{
  $out = "</table></fieldset></div> <!-- end #wrapper --></body></html>";
  return $out;
}
?>